#include "Screen.h"
#include <SDL.h>
#include <iostream>
#include <cassert>

Screen::Screen()
{	
	m_surface = 0;
	SDL_Init(SDL_INIT_EVERYTHING);
	int numJs = SDL_NumJoysticks();
	for (int i = 0; i < numJs; i++)
	{
		SDL_JoystickOpen(i);
	}
	SDL_JoystickEventState(SDL_ENABLE);
}


bool Screen::Init(int w, int h, bool isFullScreen, bool isOpenGL)
{
	int flags = SDL_SWSURFACE;
	
	if (isFullScreen)
	{
		flags |= SDL_FULLSCREEN;
	}	

	if (isOpenGL)
	{
		flags |= SDL_OPENGL;
	}

	m_isOpenGL = isOpenGL;

	m_surface = SDL_SetVideoMode(w, h, 0, flags);
	
	assert(m_surface);
	return (m_surface != 0);
}

void Screen::Flip()
{
	if(m_isOpenGL)
	{
		SDL_GL_SwapBuffers();
	}
	else
	{
		SDL_Flip(m_surface);
	}
}
SDL_Surface* Screen::GetScr()
{
	return m_surface;
}